package cn.lingyangwl.agile.infra.file.controller;

import cn.lingyangwl.agile.infra.file.assembly.FileConfigAssembly;
import cn.lingyangwl.agile.infra.file.service.FileConfigService;
import cn.lingyangwl.agile.infra.module.file.model.rqrs.*;
import cn.lingyangwl.agile.ram.ActionType;
import cn.lingyangwl.agile.ram.RamResource;
import cn.lingyangwl.framework.core.response.Resp;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 文件配置
 * 
 * @author shenguangyang
 */
@Api(tags = "文件配置")
@RestController
@RequestMapping("/fileConfig")
public class FileConfigController {
    @Resource
    private FileConfigService fileConfigService;
    @Resource
    private FileConfigAssembly fileConfigAssembly;
  
    /**
     * 分页 文件配置
     */
    @RamResource(action = "file:fileConfig:query", name = "查询文件配置", type = ActionType.READ)
    @GetMapping("/page")
    public Resp<IPage<FileConfigResp>> pageFileConfig(@Validated FileConfigPageReq query) {
        return Resp.ok(fileConfigService.pageFileConfig(query));
    }
  
    /**
     * 通过id查找 文件配置
     */
    @RamResource(action = "file:fileConfig:query", name = "查询文件配置", type = ActionType.READ)
    @GetMapping("/get")
    public Resp<FileConfigResp> getFileConfig(FileConfigGetReq req) {
        return Resp.ok(fileConfigAssembly.toFileConfResp(fileConfigService.getFileConfig(req)));
    }
  
    /**
     * 保存 文件配置
     */
    @RamResource(action = "file:fileConfig:save", name = "保存文件配置", type = ActionType.WRITE)
    @PostMapping("/save")
    public Resp<?> saveFileConfig(@Validated @RequestBody FieConfigSaveReq req) {
        return Resp.ok(fileConfigService.saveFileConfig(req));
    }

    /**
     * 更新 文件配置
     */
    @RamResource(action = "file:fileConfig:update", name = "更新文件配置", type = ActionType.WRITE)
    @PostMapping("/update")
    public Resp<?> updateFileConfigById(@Validated @RequestBody FieConfigUpdateReq req) {
        return Resp.ok(fileConfigService.updateFileConfigById(req));
    }
  
    /**
     * 批量删除 文件配置
     */
    @RamResource(action = "file:fileConfig:delete", name = "删除文件配置", type = ActionType.WRITE)
    @DeleteMapping("/batchDelete")
    public Resp<?> deleteBatch(@RequestParam(value = "ids") List<Long> ids) {
        return Resp.ok(fileConfigService.deleteFileConfigByIds(ids));
    }
  
    /**
     * 删除 文件配置
     */
    @RamResource(action = "file:fileConfig:delete", name = "删除文件配置", type = ActionType.WRITE)
    @DeleteMapping("/delete")
    public Resp<?> delete(@RequestParam(value = "id") Long id) {
        return Resp.ok(fileConfigService.deleteFileConfigById(id));
    }
}
